package com.ruoyi.business.controller.imagecontroller;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

@Service
public class ImageService {

    private final ResourceLoader resourceLoader;

    public ImageService(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    public Resource loadImageAsResource(String imageName) {
        Resource resource = resourceLoader.getResource("D:\\ruoyi\\uploadPath\\upload\\" + imageName);
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new RuntimeException("Failed to load image: " + imageName);
        }
    }
}
